package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.model.product.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("admin/product/baseCategoryTrademark/")
@RestController
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //根据category3Id获取品牌列表
    @GetMapping("findTrademarkList/{category3Id}")
    public Result findTrademarkList(@PathVariable long category3Id){
      List<BaseTrademark> baseTrademarkList = baseTrademarkService.findTrademarkList(category3Id);
        return Result.ok(baseTrademarkList);
    }

    //删除分类品牌关联
    @DeleteMapping("remove/{category3Id}/{trademarkId}")
    public Result remove(@PathVariable long category3Id,
                         @PathVariable long trademarkId){

        baseTrademarkService.removes(category3Id,trademarkId);
        return Result.ok();
    }


    //根据category3Id获取可选品牌列表
    @GetMapping("findCurrentTrademarkList/{category3Id}")
    public Result findCurrentTrademarkList(@PathVariable long category3Id){
        List<BaseTrademark> baseTrademarkList = baseTrademarkService.findCurrentTrademarkList(category3Id);
        return Result.ok(baseTrademarkList);
    }


    //保存分类品牌关联
    @PostMapping("save")
    public Result save(@RequestBody CategoryTrademarkVo categoryTrademarkVo){
        baseTrademarkService.saves(categoryTrademarkVo);
        return Result.ok();
    }

}
